package com.cloudsigns.factorymanager2.produce.adapter.produce_team;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartScheduleBean;

import java.util.ArrayList;
import java.util.List;

public class ProduceTeamOrderInformationAdapter extends BaseAdapter {
    private Context context;
    private List<WorkPartScheduleBean> workPartScheduleList = new ArrayList<>();
    private String strUnit = "";

    public ProduceTeamOrderInformationAdapter(Context context) {
        this.context = context;
    }


    public void setData(List<WorkPartScheduleBean> list) {
        this.workPartScheduleList.clear();
        if (null != list) {
            this.workPartScheduleList.addAll(list);
        }
    }

    public void setStrUnit(String strUnit) {
        this.strUnit = strUnit;
    }

    @Override
    public int getCount() {
        return workPartScheduleList.size();
    }

    @Override
    public WorkPartScheduleBean getItem(int i) {
        return workPartScheduleList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_produce_team_order_information, null);
            holder.tv_date = convertView.findViewById(R.id.tv_date);
            holder.tv_plan_num = convertView.findViewById(R.id.tv_plan_num);
            holder.tv_today_yield = convertView.findViewById(R.id.tv_today_yield);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        WorkPartScheduleBean workPartScheduleBean = workPartScheduleList.get(position);
        holder.tv_date.setText(workPartScheduleBean.getStrTime());
        holder.tv_plan_num.setText(String.valueOf(workPartScheduleBean.getAmount()) + strUnit);
        holder.tv_today_yield.setText(String.valueOf(workPartScheduleBean.getCurrentAmount()) + strUnit);

        return convertView;
    }

    static class ViewHolder {
        TextView tv_date;
        TextView tv_plan_num;
        TextView tv_today_yield;
    }
}
